package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"google.golang.org/grpc/status"
	"traning/grpc_error_message/proto"
)

func main() {
	conn, err := grpc.Dial("127.0.0.1:8080", grpc.WithInsecure())
	if err != nil {
		panic(err)
	}
	defer conn.Close()

	c := proto.NewHelloClient(conn)
	_, err = c.Hello(context.Background(), &proto.HelloRequest{Name: "？？？",
		Age: 18, Courses: []string{"123"}})

	if err != nil {
		st, ok := status.FromError(err)
		if !ok {
			panic("解析error 失败")
		}
		fmt.Println(st.Message())
		fmt.Println(st.Code())
	}
}

